<!DOCTYPE html>
<html>
<head>
  <title>${post.title!''}</title>
   <#include "../common/link.ftl">
</head>
<body>

<#include "../common/header.ftl">

<#-- 栏目区域 -->
<#include "../common/column.ftl">

<#-- 帖子详情区域 -->
<div class="layui-container">
  <div class="layui-row layui-col-space15">

    <div class="layui-col-md8 content detail">
        <#--帖子内容-->
      <div class="fly-panel detail-box">
        <h1>${post.title!''}</h1><#--标题-->
        <#--帖子状态明细-->
        <div class="fly-detail-info">
          <!-- <span class="layui-badge">审核中</span> -->
          <#--0提问,99分享,100讨论,101建议,168公告,169动态-->
          <#if post.topic == '0'>
            <a class="layui-badge">提问</a>
          <#elseif post.topic == '99'>
            <a class="layui-badge">分享</a>
          <#elseif post.topic == '100'>
            <a class="layui-badge">讨论</a>
          <#elseif post.topic == '101'>
            <a class="layui-badge">建议</a>
          <#elseif post.topic == '168'>
            <a class="layui-badge">公告</a>
          <#elseif post.topic == '169'>
            <a class="layui-badge">动态</a>
          </#if>

          <#if post.isEnd == '1'>
              <span class="layui-badge" style="background-color: #999;">未结</span>
          <#else>
              <span class="layui-badge" style="background-color: #999;">未结</span>
          </#if>

          <#--<span class="layui-badge layui-bg-black">置顶</span>
          <span class="layui-badge layui-bg-red">精帖</span>-->
          <@shiro.hasRole name="admin">
            <div class="fly-admin-box" data-id="123">
                <span class="layui-btn layui-btn-xs jie-admin" type="del">删除</span>

                <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="1">置顶</span>
                <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="0" style="background-color:#ccc;">取消置顶</span> -->

                <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="1">加精</span>
                <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="0" style="background-color:#ccc;">取消加精</span> -->
            </div>

          </@shiro.hasRole>

            <span class="fly-list-nums">
                <a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i> ${post.numReply}</a>
                <i class="iconfont" title="人气">&#xe60b;</i> ${post.numLook}
            </span>
        </div>

        <#--发帖人及编辑按钮-->
        <div class="detail-about">
          <a class="fly-avatar" href="${ctx.contextPath}/user/uid/${postuser.id!''}">
            <img src="${ctx.contextPath}${postuser.avatar!''}" alt="${postuser.username!''}">
          </a>
          <div class="fly-detail-user">
            <a href="${ctx.contextPath}/user/${postuser.id!''}" class="fly-link">
              <cite>${postuser.username!''}</cite>
              <i class="iconfont icon-renzheng" title="认证信息：${postuser.roleName!''}"></i>
            </a>
            <#if postuser.role == 'admin'>
                <i class="layui-badge fly-badge-vip layui-bg-green">管理员</i>
            </#if>
            <span>${(post.createTime!'')?string("yyyy-MM-dd")}</span>
          </div>
          <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
            <span style="padding-right: 10px; color: #FF7200">悬赏：${post.treasure!''} 财富</span>
              <@shiro.user>
                  <#if looker?? && looker.id == postuser.id>
                    <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="${ctx.contextPath}/post/edit/${post._id!''}">编辑</a></span>
                  <#else>
                    <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="${ctx.contextPath}/post/collect/${post._id!''}">收藏</a></span>
                  </#if>
              </@shiro.user>
          </div>
        </div>
        <#--帖子内容-->
        <div class="detail-body layui-text photos">
          ${post.content!''}
        </div>
      </div>

      <#--帖子回复-->
      <div class="fly-panel detail-box" id="flyReply">
        <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
          <legend>回帖</legend>
        </fieldset>

        <ul class="jieda" id="jieda">

            <#--最佳答案-->
            <#if post.reply??>
                <li data-id="${post.reply._id!''}" class="jieda-daan">
                    <a name="item-1111111111"></a>
                    <div class="detail-about detail-about-reply">
                        <a class="fly-avatar" href="${ctx.contextPath}/user/uid/${post.reply.uid!''}">
                            <img src="${ctx.contextPath}${post.reply.avatar}" alt="${post.reply.username!''}">
                        </a>
                        <div class="fly-detail-user">
                            <a href="${ctx.contextPath}/user/uid/${post.reply.uid!''}" class="fly-link">
                                <cite>${post.reply.username!''}</cite>
                            </a>
                            <#if post.reply.rolename == 'admin' >
                                <i class="layui-badge fly-badge-vip layui-bg-green">管理员</i>
                            </#if>
                            <#if post.reply.uid == post.uid>
                               <span>(楼主)</span>
                            </#if>
                        </div>

                        <div class="detail-hits">
                            <span>${(post.reply.replyTime!'')?string("yyyy-MM-dd")}</span>
                        </div>
                        <i class="iconfont icon-caina" title="最佳答案"></i>
                    </div>
                    <div class="detail-body jieda-body photos">
                        ${post.reply.content!''}
                    </div>
                    <div class="jieda-reply">
                        <span class="jieda-zan" type="zan">
                          <i class="iconfont icon-zan"></i>
                          <em>${post.reply.zan!'0'}</em>
                        </span>
                        <span type="reply">
                            <i class="iconfont icon-svgmoban53"></i>
                            回复
                        </span>
                        <div class="jieda-admin">
                            <#if looker?? && looker.id == user.id && user.role == 'admin'>
                                  <span type="del"><a class="layui-badge">删除</a></span>
                            </#if>
                        </div>
                    </div>
                </li>
            </#if>

            <#if replys??>
              <#list replys as reply>
                  <li data-id="${reply._id!''}">
                      <a name="item-1111111111"></a>
                      <div class="detail-about detail-about-reply">
                          <a class="fly-avatar" href="${ctx.contextPath}/user/uid/${reply.uid!''}">
                              <img src="${ctx.contextPath}${reply.avatar}" alt="${reply.username!''}">
                          </a>
                          <div class="fly-detail-user">
                              <a href="${ctx.contextPath}/user/uid/${reply.uid!''}" class="fly-link">
                                  <cite>${reply.username!''}</cite>
                              </a>
                              <#if reply.rolename == 'admin'>
                                <i class="layui-badge fly-badge-vip layui-bg-green">管理员</i>
                              </#if>
                              <#if reply.uid == post.uid>
                               <span>(楼主)</span>
                              </#if>

                          </div>
                          <div class="detail-hits">
                              <span>${(reply.replyTime!'')?string("yyyy-MM-dd")}</span>
                          </div>
                      </div>
                      <div class="detail-body jieda-body photos">
                          ${reply.content!''}
                      </div>
                      <div class="jieda-reply">
                          <span class="jieda-zan" type="zan">
                            <i class="iconfont icon-zan"></i>
                              <#if post.reply??>
                                  <em>${post.reply.zan!'0'}</em>
                              <#else>
                                <em>0</em>
                              </#if>
                          </span>
                          <span type="reply">
                            <i class="iconfont icon-svgmoban53"></i>
                            回复
                          </span>
                          <div class="jieda-admin">
                            <@shiro.user>
                              <#if looker?? && looker.id == user.id && user.role == 'admin'>
                                  <span type="del"><a class="layui-badge">删除</a></span>
                              </#if>
                              <#--帖子本人才可以采纳-->
                              <#if looker?? && looker.id == postuser.id && post.isEnd=='1'>
                                  <span type="accept"><a class="layui-badge">采纳</a></span>
                              </#if>
                            </@shiro.user>
                          </div>
                      </div>
                  </li>
              </#list>
            <#else >
              <#-- 无数据时 -->
              <li class="fly-none">消灭零回复</li>
            </#if>

        </ul>

        <#--回复编辑器部分-->
        <div class="layui-form layui-form-pane">
          <form action="" method="post">
            <div class="layui-form-item layui-form-text">
              <a name="comment"></a>
              <div class="layui-input-block">
                <textarea id="content" name="content" required lay-verify="required" placeholder="请输入内容"  class="layui-textarea fly-editor" style="height: 150px;"></textarea>
              </div>
            </div>
            <div class="layui-form-item">
              <input type="hidden" name="jid" value="123">
              <button class="layui-btn" lay-filter="*" lay-submit id="reply_btn">提交回复</button>
            </div>
          </form>
        </div>

      </div>
    </div>

    <div class="layui-col-md4">
      <dl class="fly-panel fly-list-one">
        <dt class="fly-panel-title">本周热议</dt>
        <#--<dd>
              <a href="jie/detail.html">基于 layui 的极简社区页面模版</a>
              <span><i class="iconfont icon-pinglun1"></i> 16</span>
          </dd>-->

          <!-- 无数据时 -->
          <div class="fly-none">没有相关数据</div>
      </dl>

      <div class="fly-panel">
        <div class="fly-panel-title">
          广告区域
        </div>
        <div class="fly-panel-main">
          <a href="#" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">广告合作区域</a>
        </div>
      </div>

    </div>

  </div>
</div>

<#include "../common/footer.ftl">

<script>
layui.cache.page = 'jie';
layui.cache.user = {
  username: '游客'
  ,uid: -1
  ,avatar: '${ctx.contextPath}/static/images/avatar/00.jpg'
  ,experience: 83
  ,sex: '男'
};
layui.config({
  version: "3.0.0"
  ,base: '${ctx.contextPath}/static/mods/'
}).extend({
  fly: 'index'
}).use(['fly', 'face', 'form', 'layer'], function(){
    var $ = layui.$, fly = layui.fly, layer = layui.layer, form = layui.form;

    //监听提交
    form.on('submit(*)', function(data){
        return false;
    });

    //如果你是采用模版自带的编辑器，你需要开启以下语句来解析。
    $('.detail-body').each(function(){
      var othis = $(this), html = othis.html();
      othis.html(fly.content(html));
    });

    //相册
    layer.photos({
        photos: '.photos',
        zIndex: 9999999999,
        closeBtn: 1,
        shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机
    });

    //提交回复
    $("#reply_btn").on("click", function () {
        var content_dom = $("#content");
        if (!mq.verify_val(content_dom)) {
            return false;
        }
        var ctx = "${ctx.contextPath}";
        var url = ctx + "/post/reply";
        var data =  {content: content_dom.val(), postId: "${post._id!''}", postTitle:"${post.title!''}"};
        mq.async(url, data, ctx);
    });

    function acceptReply (replyId){
        debugger;
        layer.confirm('是否采纳该回答为最佳答案？', function(index) {
            layer.close(index);
            var ctx = "${ctx.contextPath}";
            var url = ctx + "/accept";
            var data = {replyId: replyId};
            mq.async(url, data, ctx);
        });
    };


});
</script>

</body>
</html>